﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PlugMeterControl
{
    public partial class FormCost : Form
    {
        private bool numberEntered = false;

        public FormCost()
        {
            InitializeComponent();
        }

        private void FormCost_Shown(object sender, EventArgs e)
        {
            textConsumedPrice.Text = ConsumedPrice;
            textProducedPrice.Text = ProducedPrice;
        }

        private void buttonCostOK_Click(object sender, EventArgs e)
        {
            ConsumedPrice = textConsumedPrice.Text;
            ProducedPrice = textProducedPrice.Text;
        }

        private void buttonCostCancel_Click(object sender, EventArgs e)
        {
            Hide();
        }
        private bool CheckFixedNumber(KeyEventArgs e)
        {
            bool Numeric = false;
            if ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ||
                (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) ||
                (e.KeyCode == Keys.Back))
            {
                Numeric = true;
            }
            return Numeric;
        }

        private void textBoxFixedNr_KeyDown(object sender, KeyEventArgs e)
        {
            numberEntered = CheckFixedNumber(e);
        }

        private void textBoxFixedNr_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!numberEntered)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }
        }
    }
}
